<% blazer_title "Uploads" %>

<div id="header">
  <div class="pull-right" style="line-height: 34px;">
    <div class="btn-group">
      <%= link_to "New Upload", new_upload_path, class: "btn btn-info" %>
      <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <span class="caret"></span>
        <span class="sr-only">Toggle Dropdown</span>
      </button>
      <ul class="dropdown-menu">
        <li><%= link_to "Home", root_path %></li>
        <li><%= link_to "Checks", checks_path %></li>
        <li role="separator" class="divider"></li>
        <li><%= link_to "New Query", new_query_path %></li>
        <li><%= link_to "New Dashboard", new_dashboard_path %></li>
        <li><%= link_to "New Check", new_check_path %></li>
      </ul>
    </div>
  </div>

  <input id="search" type="text" placeholder="Start typing a table or person" style="width: 300px; display: inline-block;" class="search form-control" />
</div>

<table id="uploads" class="table">
  <thead>
    <tr>
      <th>Table</th>
      <th style="width: 60%;"></th>
      <% if Blazer.user_class %>
        <th style="width: 20%; text-align: right;">Mastermind</th>
      <% end%>
    </tr>
  </thead>
  <tbody>
    <% @uploads.each do |upload| %>
      <tr>
        <td><%= link_to upload.table, edit_upload_path(upload) %></td>
        <td><%= truncate(upload.description, length: 100, separator: " ") %></td>
        <% if Blazer.user_class %>
          <td class="creator"><%= blazer_user && upload.creator == blazer_user ? "You" : upload.creator.try(Blazer.user_name) %></td>
        <% end %>
      </tr>
    <% end %>
  </tbody>
</table>

<%= javascript_tag nonce: true do %>
  $("#search").on("keyup", function() {
    var value = $(this).val().toLowerCase()
    $("#uploads tbody tr").filter( function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    })
  }).focus()
<% end %>
